package org.example;

import java.util.Arrays;

public class Test1 {
    //leectode 274 H指数 https://leetcode.cn/problems/h-index/description/?envType=study-plan-v2&envId=top-interview-150

    /**
     * 先将数组进行排序，然后index=len(arr)-1数组从后往前遍历，prev用来记录比当前index元素大的元素个数，当arr[index]大于等于
     * prev的时候，ret就为Math.max(ret,prev)
     * @param citations
     * @return
     */
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int n = citations.length;
        int index = n - 1,prev = 0, ret = 0;
        while (index >= 0) {
            prev++;
            if (prev <= citations[index]) {
                ret = Math.max(ret,prev);
            }
            index--;
        }
        return ret;
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        int[] arr = {3,0,6,1,5};
        test1.hIndex(arr);
        System.out.println(444);
    }
}
